Re: [GENERAL] User defined function - Mailing list pgsql-general

From Herouth Maoz
Subject Re: [GENERAL] User defined function
Date
Msg-id l03130304b42faca8a73a@[147.233.159.109]
Whole thread Raw
In response to Re: [GENERAL] User defined function  ("Moray McConnachie" <moray.mcconnachie@computing-services.oxford.ac.uk>)
Responses Re: [GENERAL] User defined function
List pgsql-general
At 16:41 +0200 on 15/10/1999, Moray McConnachie wrote:


> absolutely not, I tried that already.
> I get "attribute not found" error  wherever the opening double-quotes
> are during the create of the function.

Not double quotes (The character "), but two single quotes one after the other.

Anyway, I would take a wholly different approach to this. I don't like
manipulating text and relying on the date format. I prefer working only
with dates and times. So I would use something like this:

testing=> CREATE FUNCTION dec_first( date ) RETURNS date as '
testing'>   SELECT date( date_trunc( ''year'', $1 ) - ''1 month''::timespan )'
testing-> LANGUAGE 'sql';
CREATE
testing=> select dec_first('1980-08-14');
 dec_first
----------
12-01-1979
(1 row)

testing=> select dec_first('1996-08-15');
 dec_first
----------
12-01-1995
(1 row)

testing=> select dec_first('2004-02-14');
 dec_first
----------
12-01-2003
(1 row)

Note how my doubled-quotes worked well?

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma



pgsql-general by date:

Previous
From: root
Date:
Subject: SP are good, but ....
Next
From: Jim Cromie
Date:
Subject: Re: XQL Problems